﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sails.DB
{
    /// <summary>
    /// 数据连接信息
    /// </summary>
    [Serializable]
    public class DBConnectInfo
    {
        /// <summary>
        /// 主机地址
        /// </summary>
        public string DBHost;
        /// <summary>
        /// 主机端口
        /// </summary>
        public string DBPort;
        /// <summary>
        /// 数据库名称
        /// </summary>
        public string DBName;
        /// <summary>
        /// 数据库用户名称
        /// </summary>
        public string DBUserName;
        /// <summary>
        /// 数据库用户密码
        /// </summary>
        public string DBUserPwd;

        /// <summary>
        /// 获取连接字符串
        /// </summary>
        public string ConnectStr
        {
            get
            {
                if(string.IsNullOrEmpty(DBHost) 
                    || string.IsNullOrEmpty(DBPort) 
                    || string.IsNullOrEmpty(DBName)
                    ||string.IsNullOrEmpty(DBUserName)
                    || string.IsNullOrEmpty(DBUserPwd))
                {
                    return null;
                }
                else
                {
                    return string.Format("Data Source = {0},{1};Initial Catalog = {2};User Id = {3};Password = {4};", DBHost, DBPort, DBName, DBUserName, DBUserPwd);
                }
            }
        }
    }
}
